<?php
/**
 * @version 2007.07.02
 *
 * This is the home page for the site template.
 */

// Sets up configuration settings and includes libraries.
require_once('_ini.php');
ReqLib('/lib/private/Orphanage.php');

/**
 * Defines preload page functionality;
 * this happens after DefineParams,
 * but before anything else.
 */
function DefinePreload() {//
  // Insert page preload functionality here.

  switch($_GET['Action'])
  {

  case 'Add Orphanage':
	$o = new Orphanage();

	if($_POST['OrphanageName'] != ''){

		if(!$o->Create($_POST['OrphanageName'])){
		//creation of the user failed
			if(Orphanage::GetOrphanageIdByOrphanageName($_POST['OrphanageName']) > 0)
				?>
					<script language="javascript">
						alert("Orphanage Name Already in Use!!");
					</script>
				<?
		}
		else {
			$o->ContactFirstName = $_POST['ContactFirstName'];
			$o->ContactLastName = $_POST['ContactLastName'];
			$o->ContactPhoneNumber = $_POST['ContactPhone'];
			$o->Street1 = $_POST['StreetOne'];
			$o->Street2 = $_POST['StreetTwo'];
			$o->Street3 = $_POST['StreetThree'];
			$o->City = $_POST['City'];
			$o->State = $_POST['State'];
			$o->Country = $_POST['Country'];
			$o->PostalCode = $_POST['PostalCode'];
			$o->Notes = $_POST['Notes'];

			$o->Save();

			$orphanageId = $o->OrphanageId;

		//creation of user worked

?>
	<script language="javascript">
		if(window.confirm("New Orphanage information has been added successfully.\nDo you want to add more orphanage?"))
			document.location.replace("orphanages.php");
		else
			document.location.replace("account.php");
	</script>
<?
		}
	}

	else{
	?>
		<script language="javascript">
			alert("Orphanage Name is Empty.\nEnter Orphanage Name");
		</script>
	<?
	}

  break;
  }

}

/**
 * Defines page parameters.
 *
 * @param PageParams $p
 */
function DefineParams(&$p) {
  // Define page parameters here.
}

/**
 * Defines custom header content.
 *
 */
function DefineHeader() {
  // Custom HTML info goes here,
  // just before the closing </head> tag.
}

/**
 * Defines page content.
 *
 */
function DefineContent() {
  // Page content goes here.
  ?>


<h1>Add New Orphanage</h1>
<p>
  <a href="<?=_webroot('/') ?>">Home</a>.
</p>
<p>
  <a href="account.php">My Account</a>.
</p>
<p>
  <a href="logout.php">Logout</a>.
</p>
<center>
<br />
<? if($_GET['Action'] == 'Add Orphanage') echo $GLOBALS['RegPassFail'] ?>
<br />
<form name="AddOrphanage" action="<?=_webroot('/AddOrphanage.php?Action=Add Orphanage') ?>"  method="POST">
<table>
<tr>
	<td>Orphanage Name:</td>
	<td><input type = "Text" name="OrphanageName" value = "<?php echo $_POST['OrphanageName'];?>" / ></td>
</tr>
<tr>
	<td>Contact person's First Name:</td>
	<td><input type = "Text" name ="ContactFirstName" value = "<?php echo $_POST['ContactFirstName'];?>" /></td>
</tr>
<tr>
	<td>Contact Person's Last Name:</td>
	<td><input type = "Text" name="ContactLastName" value= "<?php echo $_POST['ContactLastName'];?>" / ></td>
</tr>
<tr>
	<td>Street One: </td>
	<td><input type = "Text" name ="StreetOne" value="<?php echo $_POST['StreetOne'];?>" / ></td>
</tr>
<tr>
	<td>Street Two: </td>
	<td><input type = "Text" name ="StreetTwo" value="<?php echo $_POST['StreetTwo'];?>" / ></td>
</tr>
<tr>
	<td>Street Three: </td>
	<td><input type = "Text" name ="StreetThree" value="<?php echo $_POST['StreetThree'];?>" / ></td>
</tr>
<tr>
	<td>City: </td>
	<td><input type = "Text" name ="City" value="<?php echo $_POST['City'];?>" / ></td>
</tr>
<tr>
	<td>State or Province: </td>
	<td><input type = "Text" name ="State" value="<?php echo $_POST['State'];?>" / ></td>
</tr>
<tr>
	<td>Country: </td>
	<td><input type = "Text" name ="Country" value="<?php echo $_POST['Country'];?>" / ></td>
</tr>
<tr>
	<td>PostalCode: </td>
	<td><input type = "Text" name ="PostalCode" value="<?php echo $_POST['PostalCode'];?>" / ></td>
</tr>
<tr>
	<td>Phone Number: </td>
	<td><input type ="Text" name="ContactPhone" value ="<?php echo $_POST['ContactPhone'];?>" /> </td>
</tr>
<tr>
	<td>Anything else we should know?</td>
	<td><input type="Text" name = "Notes" value="<?php echo $_POST['Notes']?>" /></td>
</tr>
<tr >
	<td align="center"><input type="submit" value="Add Orphanage" /></td>
	<td align="center"><input type="button" value="Back" onClick="history.go(-1)" /></td>
</tr>
</table>
</form>
</center>

<?

}

// Launches the page; without this, nothing happens.
require_once('_loader.php');